package com.song.JavaThread_day04.ch4_5;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TaskMain {
	
	
	
	public static void main(String[] args) {
		
		String name ="test";
		String passwd = "test";
		UserValidator ldap = new UserValidator("ldap");
		UserValidator db = new UserValidator("db");
		
		TaskValidator ldaptask = new TaskValidator(ldap, name, passwd);
		TaskValidator dbtask = new TaskValidator(db, name, passwd);
		
		List<TaskValidator> tasklist = new ArrayList<>();
		tasklist.add(ldaptask);
		tasklist.add(dbtask);
		
		ExecutorService executor =(ExecutorService) Executors.newCachedThreadPool();
		String result;
		
			try {
				result = executor.invokeAny(tasklist);
				System.out.printf("Main : result : %s \n" ,result);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ExecutionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		executor.shutdown();
		System.out.println("Main : End of the Execution ");
		
		
	}
	
}
